# 注册 登录
from typing import Optional, List

from fastapi import APIRouter
from tortoise.expressions import Q

from core import curd
from models import Plan
from scheams import Plan_Pydantic, PlanIn_Pydantic, SuccessResponse, FailureResponse, BaseResponse

plan = APIRouter()


@plan.post("/create", summary="新增运行方案", response_model=BaseResponse)
async def create_plan(plan_form: List[PlanIn_Pydantic]):
    return await curd.create_list(Plan, plan_form)


@plan.delete("/delete", summary="删除运行方案", response_model=BaseResponse)
async def delete_plan(plan_id: int):
    return await curd.delete_by_plan_id(Plan, Plan_Pydantic, Q(plan_id=plan_id))


@plan.put("/update", summary="修改运行方案", response_model=BaseResponse)
async def update_plan(plan_id: int, plan_form: PlanIn_Pydantic):
    return await curd.update_list_by_plan_id(Plan, Plan_Pydantic, plan_form, Q(plan_id=plan_id))


@plan.get("/read", summary="获取运行方案", response_model=BaseResponse)
async def read_plan(plan_id: int):
    return await curd.get_list_by_id(Plan, Plan_Pydantic, Q(plan_id=plan_id))


@plan.get("/list", summary="获取所有运行方案", response_model=BaseResponse)
async def get_plan_list(limit: Optional[int] = 0, page: Optional[int] = 0):
    return await curd.get_list(Plan, Plan_Pydantic, page, limit)
